<?php
namespace app\Tool;

class Str
{
    public static $str = '';

    public static function random( $length = 43 ,$type = 'number')
    {

        switch ($type){
            case 'number' :
                $chars = '0123456789';
                break;
            case 'letter' :
                $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                break;
            case 'mixture' :
                $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
                break;
            default :
                throw new \Exception('参数错误');
        }

        for ( $i = 0; $i < $length; $i++ )
        {
            self::$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        }

        return self::$str;
    }
}